from django.template import Library
from web import models
from django.urls import reverse

register = Library()


# """管理中心界面项目列表"""
@register.inclusion_tag("inclusion/all_project_list.html")
def all_project_list(request):
    # 获取当前用户创建的项目
    my_project_list = models.ProjectInfo.objects.filter(create_user=request.tracer.user)
    # 获取当前用户参与的项目
    join_project_list = models.ParticipatorInfo.objects.filter(participator=request.tracer.user, status=1)

    return {"my": my_project_list, "join": join_project_list,'request':request}


# """管理中心界面菜单列表"""
@register.inclusion_tag("inclusion/manage_menu_list.html")
def manage_menu_list(request):
    menu_list = [
        {"title": "概览", 'url': reverse("dashboard", kwargs={'project_id': request.tracer.project.id})},
        {"title": "问题", "url": reverse("issues", kwargs={'project_id': request.tracer.project.id})},
        {"title": "统计", "url": reverse("total", kwargs={'project_id': request.tracer.project.id})},
        {"title": "wiki", "url": reverse("wiki", kwargs={'project_id': request.tracer.project.id})},
        {"title": "文件", "url": reverse("file", kwargs={'project_id': request.tracer.project.id})},
        {"title": "配置", "url": reverse("setting", kwargs={'project_id': request.tracer.project.id})},
    ]
    # 设置 当前选中的菜单
    for item in menu_list:
        if request.path_info.startswith(item['url']):
            item['class']='active'
    return {"data_list": menu_list,'request':request}
